#ifndef PHOTOBOOTH_H_INCLUDED
#define PHOTOBOOTH_H_INCLUDED

#include <string>

#include "ofMain.h"
#include "BalanceMeter.h"
#include "ofxFileTransferManager.h"

#include "ofxOsc.h"

//#define ENABLE_RESIZING

#define camWidth 640
#define camHeight 480
#define camTop 330
#define camBottom 150

#define PORT 8766
#define NUM_MSG_STRINGS 20


void drawTtfStringCentered( ofTrueTypeFont& font, const std::string& s, int x, int y );

class PhotoBooth : public ofBaseApp
{


public:


    enum PB_STATE
    {
        PB_STATE_INSTRUCT,
        PB_STATE_TAKEPICTURE,
        PB_STATE_VIEWHEAD,
        PB_STATE_METER,
        PB_STATE_FINISHED,
        PB_STATE_PLAYERSTATUS,
        PB_STATE_SHOWSNAPSHOT,
        PB_STATE_FINISH,
    };

    static const string GAME_IP;
    static const int GAME_PORT;

    static const string SCOREBOARD_IP;
    static const int SCOREBOARD_PORT;

    void setup();
    void update();
    void draw();

    void eventReceived();
    void updateSnapshot();
    void chromaKey();
    void chromaKeyHSV();
    void saveSnapshotImages();
    void RGBtoHSV( float r, float g, float b );
    void receiveMessage();
    void states();
    void setMasks();

    float MINRGB(float r,float g, float b);
    float MAXRGB(float r, float g, float b);

    float h;
    float s;
    float v;

    int hh;
    float ss;
    float vv;

    void keyPressed(int key);

    void camera();

    void setDateName();
    void moveMeter();

    void setState(PB_STATE newState);

    int meterValue();

    void redrawMeter();

    PB_STATE getState();



private:

    BalanceMeter balance;

    ofImage snapshot;
    ofImage topSnapshot;
    ofImage bottomSnapshot;
    ofImage outputImageTop;
    ofImage outputImageBottom;
    ofImage contourImage;
    ofImage outputTemp;
    ofImage greenInfo;
    ofImage orangeInfo;
    ofImage purpleInfo;

    unsigned char bottomPixels[camWidth * camHeight * 4];
    unsigned char topPixels[camWidth * camHeight * 4];

    ofVideoGrabber vidGrabber;

    ofxFileTransferManager fileManager;

    int totalPixels;
    int totalPixelsTop;
    int totalPixelsBottom;
    int counter;
    int getTime;
    int getTime2;

    int culture;
    int culture2;
    int industry;
    int iPercentage;
    int cPercentage;

    int screenWidth;
    int screenHeight;

    float mask;
    float mask2;
    int maskR;
    int maskG;
    int maskB;

    string Month;
    string Day;
    string Hour;
    string Minute;
    string Second;
    string dateNameTop;
    string dateNameBottom;
    string Culture;
    string Industry;
    string Player;



    unsigned char * snapshotPixels;
    unsigned char * framePixels;

    bool snapshotTaken;
    bool Meter;
    bool pictureSaved;

    ofTrueTypeFont  franklinBook;
    ofTrueTypeFont  franklinBook2;
    ofTrueTypeFont  OLDENGL;
    ofTrueTypeFont  OLDENGL2;
    ofTrueTypeFont  vgafix;
    ofTrueTypeFont  vgafix2;
    ofTrueTypeFont  nyala;
    ofTrueTypeFont  nyala2;
    ofTrueTypeFont  nyala3;

    ofImage balanceMeter;
    ofImage balancePointer;
    ofImage balanceMeterVert;
    ofImage balanceWijzerHead;
    ofImage balanceMeterG;
    ofImage balanceMeterO;
    ofImage balanceMeterP;
    ofImage logo;
    ofImage logoBig;

    ofPoint topleft;
    ofPoint topleft2;

    string toPaddedString(double value, int padLength);

    PB_STATE pbState;

    ofxOscReceiver	receiver;

    int				current_msg_string;
    string		msg_strings[NUM_MSG_STRINGS];
    float			timers[NUM_MSG_STRINGS];
    int playerAmount;
    int player;

    string freePlayers;

    int cancelTime;
    int finishedWaitingTime;
    int showSnapshotTime;

    int time3;

    int startX;
    int startY;
    int stepY;

    int screenCenter;
    int screenRight;

    bool buttonPressed;
    int balanceStateWait;

    ofImage greenJoystick;
    ofImage purpleJoystick;
    ofImage orangeJoystick;
    //ofxOscMessage m;


};



#endif // PHOTOBOOTH_H_INCLUDED
